import pygame



class Radar():
	COLKEY=(0,0,7)
	GREEN=(58,154,59)

	def __init__(self,pitch,scale,offset,viewportoffset,itemsize):
		self.__pitch=pitch
		self.__scale=scale
		self.__offset= offset
		self.__itemsize= itemsize

		pitch_rect= self.__pitch.get_rect()
		height=pitch_rect.height*self.__scale
		width=pitch_rect.width*self.__scale

		self.__rect= pygame.Rect(offset[0],offset[1],width,height)

        #hash of items ...
	def set_radar_items(self,items):
		self.__radar_items=items

	def blit_to(self,screen):
		#screen.blit(self.__surface,self.__offset)
		pygame.draw.rect(screen,(255,255,255),self.__rect,1)
		
	def update_positions(self, positions,screen):
		for k in positions:
#			if positions[k] != self.__radar_items[k].pos:
				self.blit_item(self.__radar_items[k].pos, positions[k], self.__radar_items[k].colour,screen)
				self.__radar_items[k].pos= positions[k]
	
	def blit_item(self,pitch_pos_old,pitch_pos,colour,screen):
		if pitch_pos_old!=pitch_pos:
			pygame.draw.rect(screen, self.GREEN,pygame.Rect((self.__offset[0]+pitch_pos_old[0]*self.__scale,self.__offset[1]+pitch_pos_old[1]*self.__scale),self.__itemsize))
			pygame.draw.rect(screen, colour,pygame.Rect((self.__offset[0]+pitch_pos[0]*self.__scale,self.__offset[1]+pitch_pos[1]*self.__scale),self.__itemsize))
